package mobi.hami.huapin.dao;

import mobi.hami.huapin.model.NoteSchedule;

import java.text.MessageFormat;
import java.util.List;
import java.util.Map;

public class NoteScheduleProvider {

    /**
     * 多条件查询
     * @param parms
     * @return
     */
    public String selectWitchParam(Map<String,Object> parms){
        StringBuilder sb = new StringBuilder();
        sb.append("select * from note_schedule where ");
        if(null != parms && !parms.isEmpty()){
            if(null != parms.get("sort_id") && !parms.get("sort_id").equals("")){
                sb.append("sort_id = ").append(parms.get("sort_id")).append(" and ");
            }
            if(null != parms.get("order_num") && !parms.get("order_num").equals("")){
                sb.append("order_num = ").append(parms.get("order_num")).append(" and ");
            }
        }
        sb.append("1 = 1 ");
        sb.append("group by order_num order by start_time desc");
        return sb.toString();
    }

    /**
     * 批量插入
     */
    public String batchAdd(Map map){
        StringBuilder sb = new StringBuilder();
        List<NoteSchedule> list = (List<NoteSchedule>) map.get("list");
        sb.append("INSERT INTO note_schedule (note_id,sort_id,content,order_num,status) VALUES ");
        MessageFormat mf = new MessageFormat(
                "(#'{'list[{0}].note_id}, #'{'list[{0}].sort_id}, #'{'list[{0}].content},#'{'list[{0}].order_num},#'{'list[{0}].status})"
        );
        for (int i = 0; i < list.size(); i++) {
            sb.append(mf.format(new Object[] {i}));
            if (i < list.size() - 1)
                sb.append(",");
        }
        return sb.toString();
    }


}
